/*

*/

clear all

adopath ++/afs/umich.edu/group/m/mmcmps/ado

// MACROS
global funding "Y:/limited/Michigan_CTE/funding_change"


use ${funding}/data_final/compiled_student_analysis_data.dta, clear



***
* A5: Impacts on Assessment Scores
***


preserve
keep if grad_year >= 2012
replace c2014 = 0

gen cte_tested_part = 0
gen cte_tested_conc = 0
gen cte_tested_comp = 0
gen cte_took_test_anyprog = 0


foreach cip in "43.0100" "47.0603"  "47.0604"  "47.0613" "51.0000" "52.0299" "52.0800" "52.1999" {
	
	local cipnodot = subinstr(`"`cip'"',".","",.)
	
	replace cte_tested_part = 1 if cte_part_prog`cipnodot' ==1
	replace cte_tested_conc = 1 if cte_conc_prog`cipnodot' ==1
	replace cte_tested_comp = 1 if cte_comp_prog`cipnodot' ==1
	replace cte_took_test_anyprog = 1 if took_test_prog`cipnodot' ==1
	
}



// SPECIFY CONTROL VARIABLES
local demographics female black hisp another_race sped lep econdis
*local academics test_avg_g8 test_avg_sq_g8 test_avg_g8_imp attendance_g8 attendance_g8_imp
local academics test_avg_g8_imp attendance_g8 attendance_g8_imp


// RUN REGRESSIONS
gen cohort = .

gen score_over_time = .
gen score_over_time_l95 = .
gen score_over_time_u95 = .
gen took_over_time = .
gen took_over_time_l95 = .
gen took_over_time_u95 = .


eststo clear


eststo: reghdfe cte_best_score c2012-c2019 `demographics' `academics' if cte_test_any==1, a(school) vce(cluster school)
*eststo: reghdfe test_avg_g8 c2012-c2019 `demographics' `academics' if cte_test_any==1, a(school) vce(cluster school)
*gen dif = cte_best_score - test_avg_g8
*eststo: reghdfe dif c2012-c2019 `demographics' `academics' if cte_test_any==1, a(school) vce(cluster school)

local i = 1
forvalues x = 2012/2019 {
	replace cohort = `x' if cohort==. in `i'
  replace score_over_time =   _b[c`x'] in `i'
  replace score_over_time_l95 =   _b[c`x'] - (invttail(e(df_r),0.025) *   _se[c`x']) in `i'
  replace score_over_time_u95 =   _b[c`x'] + (invttail(e(df_r),0.025) *  _se[c`x']) in `i'
  local ++i
}



eststo: reghdfe cte_took_test_anyprog c2012-c2019 `demographics' `academics', a(school) vce(cluster school)
*eststo: reghdfe test_avg_g8 c2012-c2019 , a(school) vce(cluster school)



local i = 1
forvalues x = 2012/2019 {
  replace took_over_time = 100 * _b[c`x'] in `i'
  replace took_over_time_l95 = 100 * _b[c`x'] - (invttail(e(df_r),0.025) * 100 * _se[c`x']) in `i'
  replace took_over_time_u95 = 100 * _b[c`x'] + (invttail(e(df_r),0.025) * 100 * _se[c`x']) in `i'
  local ++i
}

keep cohort  took_over* score_over*
drop if cohort == .


// DRAW GRAPH - WIDER
tw (rarea took_over_time_l95 took_over_time_u95 cohort, color("$color1int") lwidth(none)) ///
   (connected took_over_time cohort, sort lc("$color1") lp(solid) mc("$color1")) ///
   (pci -5 2015.2 10 2015.2 (1) "Funding Change", lc(gs8) recast(pccapsym) msymbol(i) mlabc(gs8) mlabs(medlarge)) ///
   (pci -5 2014.7 10 2014.7, lc(gs8%14) lw(16)), ///
   xlabel(2012(1)2019, labsize(medlarge)) ///
   xtitle(" " "Cohort Graduation Year", size(medlarge)) ///
   ylabel(-5(2.5)10, angle(0) gmax glc(gs15) glw(thin) labsize(medlarge) format(%3.1f)) ///
   ytitle("Percentage Point Change" " " , size(medlarge)) ///
   legend(order(2 "Took CTE Assessment") rows(1) size(medlarge)) ///
   graphregion(color(white)) bgcolor(white) plotregion(margin( 10 10 0 0)) xsize(9)

 
*graph save ${funding}/output/graphs/temp/t1.gph, replace


// DRAW GRAPH - WIDER
tw (rarea score_over_time_l95 score_over_time_u95 cohort, color("$color1int") lwidth(none)) ///
   (connected score_over_time cohort, sort lc("$color1") lp(solid) mc("$color1")) ///
   (pci -.4 2015.2 .3 2015.2 (1) "Funding Change", lc(gs8) recast(pccapsym) msymbol(i) mlabc(gs8) mlabs(medlarge)) ///
   (pci -.4 2014.7 .3 2014.7, lc(gs8%14) lw(16)), ///
   xlabel(2012(1)2019, labsize(medlarge)) ///
   xtitle(" " "Cohort Graduation Year", size(medlarge)) ///
   ylabel(-.4(.1).3, angle(0) gmax glc(gs15) glw(thin) labsize(medlarge) format(%2.1f)) ///
   ytitle("Change in Scores (SD)" " " , size(medlarge)) ///
   legend(order(2 "Average Scores") rows(1) size(medlarge)) ///
   graphregion(color(white)) bgcolor(white) plotregion(margin( 10 10 0 0)) xsize(9)


graph save ${funding}/output/graphs/temp/t2.gph, replace

//COMBINE
graph combine ${funding}/output/graphs/temp/t1.gph ${funding}/output/graphs/temp/t2.gph, ///
	 xsize(10) graphregion(color(white)) 

graph save ${funding}/output/graphs/fig06_assess.gph, replace

   
  